package com.example.xm.ui.home.fragments;

import android.content.Intent;
import android.view.View;
import android.widget.TextView;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.xm.R;
import com.example.xm.adapter.HomeAdapter.HomeVideoAdapter;
import com.example.xm.base.BaseAdapter;
import com.example.xm.base.BaseFragment;
import com.example.xm.bean.HomeBean.HomeArticleBean;
import com.example.xm.bean.HomeBean.HomeBannderBean;
import com.example.xm.bean.HomeBean.HomeHotUserBean;
import com.example.xm.bean.HomeBean.HomePhotoBean;
import com.example.xm.bean.HomeBean.HomeRecommendBean;
import com.example.xm.bean.HomeBean.HomeRewardBean;
import com.example.xm.bean.HomeBean.HomeSquareBean;
import com.example.xm.bean.HomeBean.HomeTopicDiscussedBean;
import com.example.xm.bean.HomeBean.HomeVideoBean;
import com.example.xm.common.VideoItemDecoration;
import com.example.xm.interfaces.home.IHome;
import com.example.xm.presenter.home.RecommendPresenter;
import com.example.xm.ui.home.activity.VideoActivity;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

public class Fragment_Video extends BaseFragment<IHome.RecommendPersenter> implements IHome.RecommendView {

    @BindView(R.id.tv_tab_all)
    TextView tvTabAll;
    @BindView(R.id.tv_tab_fujin)
    TextView tvTabFujin;
    @BindView(R.id.v)
    View v;
    @BindView(R.id.rlv_video)
    RecyclerView rlvVideo;
    private ArrayList<HomeVideoBean.DataBean.ListBean> list;
    private HomeVideoAdapter homeVideoAdapter;
    private HomeVideoBean.DataBean dataBeans;

    @Override
    protected IHome.RecommendPersenter initPresenter() {
        return new RecommendPresenter();
    }

    @Override
    protected int getLayout() {
        return R.layout.fragment_video;
    }

    @Override
    protected void initView() {
        list = new ArrayList<>();
        rlvVideo.setLayoutManager(new GridLayoutManager(getActivity(), 2));
        VideoItemDecoration videoItemDecoration = new VideoItemDecoration();
        videoItemDecoration.setPace(20);
        rlvVideo.addItemDecoration(videoItemDecoration);
        homeVideoAdapter = new HomeVideoAdapter(getActivity(), list);
        rlvVideo.setAdapter(homeVideoAdapter);
    }

    @Override
    protected void initData() {
        mPresenter.getVideo();
    }

    @Override
    protected void initListener() {
        homeVideoAdapter.setOnClick(new BaseAdapter.onClick() {
            @Override
            public void click(int pos) {
                Intent intent = new Intent(getActivity(), VideoActivity.class);
                intent.putExtra("pos",pos);
                intent.putExtra("videos",dataBeans);
                startActivity(intent);
            }
        });
    }

    @Override
    public void showTips(String tips) {

    }

    @Override
    public void showLoading(int visble) {

    }

    @Override
    public void getBannerReturn(HomeBannderBean result) {

    }

    @Override
    public void getTopicDiscussedReturn(HomeTopicDiscussedBean result) {

    }

    @Override
    public void getRecommendReturn(HomeRecommendBean result) {

    }

    @Override
    public void getHotUserReturn(HomeHotUserBean result) {

    }

    @Override
    public void getSquareReturn(HomeSquareBean result) {

    }

    @Override
    public void getVideoReturn(HomeVideoBean result) {
        if (result.getStatus().getStatusCode() == 100) {
            List<HomeVideoBean.DataBean.ListBean> list = result.getData().getList();
            HomeVideoBean.DataBean data = result.getData();
            dataBeans=data;
            this.list.addAll(list);
            homeVideoAdapter.notifyDataSetChanged();
        }
    }

    @Override
    public void getPhotoReturn(HomePhotoBean result) {

    }

    @Override
    public void getHomeArticleReturn(HomeArticleBean result) {

    }

    @Override
    public void getHomeRewardReturn(HomeRewardBean result) {

    }
}
